<template>
  <div class="login-container">
    <el-form
      ref="loginForm"
      class="login-form"
      label-position="left"
      :model="loginForm"
      :rules="loginRules"
    >
      <!-- logo部分 留下 -->
      <div class="title-container">
        <h3 class="title">
          <img src="../../assets/logo.595745bd.png" alt="">
        </h3>
      </div>
      <el-form-item prop="account">
        <span class="svg-container el-icon-user-solid" />
        <el-input v-model.trim="loginForm.account" placeholder="请输入账号" />
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container el-icon-user-solid" />
        <el-input
          ref="pwdInput"
          v-model.trim="loginForm.password"
          placeholder="请输入密码"
          :type="type"
        />
        <span class="svg-container" @click="changePwd">
          <svg-icon
            :icon-class="`${type === 'password' ? 'eye' : 'eye-open'}`"
          />
        </span>
      </el-form-item>
      <el-form-item prop="code">
        <span class="svg-container el-icon-user-solid" />
        <el-input v-model.trim="loginForm.code" placeholder="请输入验证码" />
      </el-form-item>
      <!-- 按钮 留下 -->
      <el-button class="loginBtn" @click="submitLogin">Login</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        account: 'admin',
        password: 'admin',
        code: '',
        loginType: 0
      },
      type: 'password',
      loginRules: {
        account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        code: [{ required: true, message: '请输入账号', trigger: 'blur' }]
      }
    }
  },
  methods: {
    changePwd() {
      this.type = this.type === 'password' ? '' : 'password'
      this.$nextTick(() => {
        this.$refs.pwdInput.focus()
      })
    },
    submitLogin() {
      this.$refs.loginForm.validate((val) => {
        if (val) {
          try {
            this.$store.dispatch('user/getLoginInfo', this.loginForm)
          } catch (error) {
            console.log(error)
          }
        }
      })
    }
  }
}
</script>

<style lang="scss">
$bg: #283443;
$light_gray: #68b0fe;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    color: #454545;
  }
  .el-form-item__error {
    color: #f56c6c;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #68b0fe;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;
  background-image: url('../../assets/background.be4fae7d.png');
  background-repeat: no-repeat;
  background-size: cover;
  .login-form {
    position: absolute;
    width: 518px;
    height: 388px;
    top: 50%;
    left: 50%;
    margin-top: -194px;
    margin-left: -259px;
    padding: 50px 35px 0;
    background: #fff;
    box-shadow: 0 3px 70px 0 rgb(30 111 72 / 35%);
    border-radius: 10px;
    .el-form-item {
      border: 1px solid #e2e2e2;
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      img {
        position: absolute;
        width: 96px;
        height: 96px;
        top: -110px;
        left: 50%;
        margin-left: -48px;
      }
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .loginBtn {
    color: #fff;
    background: #407ffe;
    height: 64px;
    line-height: 32px;
    font-size: 24px;
    width: 100%;
    margin-bottom: 30px;
  }
}
</style>
